package com.cleaningcloud.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.ErpSupplier;
import com.cleaningcloud.erp.service.IErpSupplierService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 供应商管理Controller
 * 
 * @author cleaningcloud
 * @date 2024-09-25
 */
@RestController
@RequestMapping("/ErpSupplier")
public class ErpSupplierController extends BaseController
{
    @Autowired
    private IErpSupplierService erpSupplierService;

    /**
     * 查询供应商管理列表
     */
    @RequiresPermissions("erp:ErpSupplier:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpSupplier erpSupplier)
    {
        startPage();
        List<ErpSupplier> list = erpSupplierService.selectErpSupplierList(erpSupplier);
        return getDataTable(list);
    }


    /**
     * 查询供应商管理列表
     */
//    @RequiresPermissions("erp:ErpSupplier:list")
    @GetMapping("/getList")
    public AjaxResult list()
    {
        return success(erpSupplierService.getList());
    }

    /**
     * 导出供应商管理列表
     */
    @RequiresPermissions("erp:ErpSupplier:export")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpSupplier erpSupplier)
    {
        List<ErpSupplier> list = erpSupplierService.selectErpSupplierList(erpSupplier);
        ExcelUtil<ErpSupplier> util = new ExcelUtil<ErpSupplier>(ErpSupplier.class);
        util.exportExcel(response, list, "供应商管理数据");
    }

    /**
     * 获取供应商管理详细信息
     */
    @RequiresPermissions("erp:ErpSupplier:query")
    @GetMapping(value = "/{supplierId}")
    public AjaxResult getInfo(@PathVariable("supplierId") Long supplierId)
    {
        return success(erpSupplierService.selectErpSupplierBySupplierId(supplierId));
    }


    /**
     * 获取自增组件下一位
     */
    @GetMapping(value = "/getAutoIncrement")
    public AjaxResult getAutoIncrement()
    {
        return success(erpSupplierService.getAutoIncrement());
    }

    /**
     * 新增供应商管理
     */
    @RequiresPermissions("erp:ErpSupplier:add")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpSupplier erpSupplier)
    {
        return toAjax(erpSupplierService.insertErpSupplier(erpSupplier));
    }

    /**
     * 修改供应商管理
     */
    @RequiresPermissions("erp:ErpSupplier:edit")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpSupplier erpSupplier)
    {
        return toAjax(erpSupplierService.updateErpSupplier(erpSupplier));
    }

    /**
     * 删除供应商管理
     */
    @RequiresPermissions("erp:ErpSupplier:remove")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{supplierIds}")
    public AjaxResult remove(@PathVariable Long[] supplierIds)
    {
        return toAjax(erpSupplierService.deleteErpSupplierBySupplierIds(supplierIds));
    }
}
